﻿using Natural.Attributes;
using Natural.Model;
using Natural.Providers;

namespace Natural.Observers
{
    [Impl(Type = ImplType.Observer, Name = "Update", Strategy = "Behavior", ApplyTo = typeof(DeviceLocation), Version = 0, Priority = 0)]
    public class UpdateLogObsever<T> where T : class
    {
        public virtual void Notify(ActionContext context, DeviceLocation entity, string includes)
        {
            Device device = Data.First<Device>(new Expression("this.Id = @Id", new Parameters() { { "Id", entity.DeviceId } }));
            device.LocationId = entity.Id;
            Executor.Update<Device>(context, device);
        }
    }
}
